

export const temperaturePoint = {
  p1: {
    x: null,
    y: null
  },
  p2: {
    x: null,
    y: null
  },
  p3: {
    x: null,
    y: null
  },
  p4: {
    x: null,
    y: null
  },
  p5: {
    x: null,
    y: null
  },
  p6: {
    x: null,
    y: null
  }
}

export const positionPoint = {
  a1: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  },
  a2: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  },
  a3: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  },
  a4: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  },
  a5: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  },
  a6: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  },
  line: {
    x1: null,
    y1: null,
    x2: null,
    y2: null
  }
}

export const filterOnline = (h, online) => {
  if (online) return h('Tag', {
    props: {
      color: "green"
    }
  }, '在线');
  else return h({
    props: {
      color: "gray"
    }
  }, '离线');
};

export const filterState = (h, state) => {
  let stateObject = {
    1: h('Tag', {
      props: {
        color: "green"
      }
    }, '正常'),
    2: h('Tag', {
      props: {
        color: "yellow"
      }
    }, '预警'),
    3: h('Tag', {
      props: {
        color: "red"
      }
    }, '告警'),
    4: h('Tag', {
      props: {
        color: "gray"
      }
    }, '故障')
  }
  if (!(state in stateObject)) {
    return h('Tag', {
      props: {
        color: "#909399"
      }
    }, '未知');
  }
  return stateObject[state]
}


export const refsList = {
  p1: ['p1xRef', 'p1yRef'],
  p2: ["p2xRef", 'p2yRef'],
  p3: ["p3xRef", "p3yRef"],
  p4: ["p4xRef", "p4yRef"],
  p5: ["p5xRef", "p5yRef"],
  p6: ["p6xRef", "p6yRef"],
  a1: ["a1x1Ref", "a1y1Ref", "a1x2Ref", "a1y2Ref"],
  a2: ["a2x1Ref", "a2y1Ref", "a2x2Ref", "a2y2Ref"],
  a3: ["a3x1Ref", "a3y1Ref", "a3x2Ref", "a3y2Ref"],
  a4: ["a4a1Ref", "a4y1Ref", "a4x2Ref", "a4y2Ref"],
  a5: ["a5x1Ref", "a5y1Ref", "a5x2Ref", "a5y2Ref"],
  a6: ["a6x1Ref", "a6y1Ref", "a6x2Ref", "a6y2Ref"],
  line: ["linex1Ref", "liney1Ref", "linex2Ref", "liney2Ref"]
}
const pointArr = Object.keys(refsList);
export const whichIsTrue = vm => {
  let newArr = [];
  pointArr.forEach(t => {
    if (vm[t]) {
      newArr.push(refsList[t]);
    }
  })
  return newArr;
}

export const isValidate = (newArr, vm) => {
  let trueAndFalseArr = [];
  return new Promise((resolve, reject) => {
    try {
      newArr.forEach(t => {
        t.forEach(item => {
          vm.$refs[item].submit(t => {
            trueAndFalseArr.push(t);
          })
        })
      })
      resolve(trueAndFalseArr);
    } catch (e) {
      reject(e)
    }

  })
}


export const hasFalseInArray = arr => {
  if (arr.indexOf(false) === -1) return true
  else return false
}
